﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Linq;
using CBM.Contract.Shell;
using CBM.Container;
using System.Collections.ObjectModel;
using Microsoft.Practices.Unity;
using StripboekManager.Contract.Command;
using Caliburn.Micro;
using StripboekManager.Contract.ViewModel;

namespace CBM
{
    public class ShellViewModel : PropertyChangedBase/*, IShell*/
    {
        private IUnityContainer containerField;
        public ShellViewModel()
        {
            containerField = new ComicBookContainer();
        }

        private ObservableCollection<ICBMCommand> menuOptionsField;
        public System.Collections.ObjectModel.ObservableCollection<ICBMCommand> MenuOptions
        {
            get
            {
                if (menuOptionsField == null)
                {
                    ICBMCommand command = containerField.Resolve<ICBMCommand>();
                    command.Caption = "TesT";
                    command.Name = "TesT";
                    ICBMCommand command2 = containerField.Resolve<ICBMCommand>();
                    command2.Caption = "TesT2";
                    command2.Name = "TesT2";
                    ICBMCommand command3 = containerField.Resolve<ICBMCommand>();
                    command3.Caption = "TesT3";
                    command3.Name = "TesT3";
                    ICBMCommand command4 = containerField.Resolve<ICBMCommand>();
                    command4.Caption = "TesT4";
                    command4.Name = "TesT4";

                    menuOptionsField = new ObservableCollection<ICBMCommand> { command, command2, command3, command4 };                
                }
                return menuOptionsField;
            }
        }
        
        public void OpenMenuItem(string name)
        {
            ICBMCommand command = MenuOptions.Where(x => x.Name == name).FirstOrDefault();
            CurrentViewModel = command.GetView();
        }

        private IViewModel currentViewModelField;
        public IViewModel CurrentViewModel
        {
            get
            {
                return currentViewModelField;
            }
            private set
            {
                currentViewModelField = value;
                NotifyOfPropertyChange("CurrentViewModel");
            }
        }
    }
}
